package com.xiaomengkuan.test.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Faraj Mujey
 * -- Creation Time: 2021-01-01 9:28 下午, File Encoding: utf8 --
 */
@Data
public class R {
    private int code;
    private Map<String, Object> data;

    protected void setCode(int code){
        this.code = code;
    }

    protected void setData(Map<String,Object> data){
        this.data = data;
    }

    protected void setData(String key, Object value) {
        this.data.put(key, value);
    }

    public static R OK(){
        R r = new R();
        r.data = new HashMap<>();
        r.setCode(200);
        return r;
    }

    public R put(Map<String, Object> data){
        setData(data);
        return this;
    }

    public R put(String key, Object value) {
        setData(key, value);
        return this;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", data=" + data +
                '}';
    }
}
